/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved. 
 */
package com.icinfo.cloud.provider.punish.config.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.config.dto.ConfigApprovalFlowAutoRequest;
import com.icinfo.cloud.provider.punish.config.dto.ConfigDocumentApprovalFlowAutoRelation;
import com.icinfo.cloud.provider.punish.config.dto.ConfigDocumentApprovalFlowAutoSaveDto;
import com.icinfo.cloud.provider.punish.config.service.IConfigApprovalFlowAutoService;
import com.icinfo.cloud.provider.punish.config.vo.ConfigAllRoleInfoVo;
import com.icinfo.cloud.provider.punish.config.vo.ConfigApprovalFlowAutoVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述:  config_approval_flow_auto 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年12月05日
 */
@RestController
@RequestMapping("/punish/config/configApprovalFlowAuto")
public class ConfigApprovalFlowAutoController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(ConfigApprovalFlowAutoController.class);

    @Autowired
    private IConfigApprovalFlowAutoService configApprovalFlowAutoService;

    /**
     * 自动审批配置列表
     * @author liyafeng
     * @date 2022/12/5
      * @param request
     * @return {@link Result< PageResponse< ConfigApprovalFlowAutoVo>>}
     */
    @PostMapping("/getlist")
    public Result<List<ConfigApprovalFlowAutoVo>> list(@RequestBody @Validated ConfigApprovalFlowAutoRequest request) {
        List<ConfigApprovalFlowAutoVo> configApprovalFlowAutoVos=configApprovalFlowAutoService.getConfigApprovalFlowAutoVoList(request);
        return Result.success("获取成功",configApprovalFlowAutoVos);
    }

    /**
     * 自动审批配置
     * @author liyafeng
     * @date 2022/12/5
     * @param saveDto
     * @return {@link Result< PageResponse< ConfigApprovalFlowAutoVo>>}
     */
    @PostMapping("/saveConfigDocumentApprovalFlowAuto")
    public Result<String> list(@RequestBody @Validated ConfigDocumentApprovalFlowAutoSaveDto saveDto) {
        List<ConfigDocumentApprovalFlowAutoRelation> list=saveDto.getConfigDocumentApprovalFlowAutoRelations();
        if(ObjectUtils.isEmpty(list)){
            return Result.error("配置失败,自动审批关系不能为空");
        }else{
            boolean isAllAuto=true;
            for (ConfigDocumentApprovalFlowAutoRelation configDocumentApprovalFlowAutoRelation:list) {
                if(Constant.STRING_0.equals(configDocumentApprovalFlowAutoRelation.getIsAutoFlow())){
                    isAllAuto=false;
                    break;
                }
            }
            /*if(!isAllAuto){
                return Result.error("配置失败,自动审批信息需要全部配置，请补全");
            }*/
        }
        int num=configApprovalFlowAutoService.saveConfigDocumentApprovalFlowAuto(saveDto);
        if(num>0){
            return Result.success("配置成功");
        }
        return Result.error("配置失败");
    }
    /**
     * 根据审批流查看所有角色信息
     * @author liyafeng
     * @date 2022/12/11
      * @param  approvalFolwId
     * @return {@link Result< String>}
     */
    @GetMapping("/getApprovalRoleInfoByApprovalFolwId")
    public Result<ConfigAllRoleInfoVo> getApprovalRoleInfoByApprovalFolwId(@RequestParam  String  approvalFolwId) {
        ConfigAllRoleInfoVo vo=configApprovalFlowAutoService.getApprovalRoleInfoByApprovalFolwId(approvalFolwId);
        return Result.success("获取成功",vo);
    }



}